package org.hongqi.common.senpec.sys.user;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Transient;
import lombok.*;
import org.hongqi.common.senpec.base.mybatisplus.IBaseEntity;
import org.hongqi.common.senpec.sys.department.Department;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;

@EqualsAndHashCode(callSuper = true)
@Data
@Builder
@NoArgsConstructor(force = true)
@AllArgsConstructor
@Entity(name = "senpec_sys_user")
@TableName("senpec_sys_user")
public class User extends IBaseEntity<User> implements UserDetails {
    @Column(length = 20)
    private String name;
    @Column(length = 30, unique = true)
    private String username;
    @Column(length = 200)
    private String password;
    @Column(length = 30, unique = true)
    private String email;
    @Column(length = 18, unique = true)
    private String idCard;
    @Column(length = 10, unique = true)
    private String jobno;
    @Column(length = 20, unique = true)
    private String phone;
    @Column(length = 1)
    private String gender = "空";
    private Long department;
    @Transient
    @TableField(exist = false)
    private Department departmentObj;//员工部门对应的实体类
    @Column(length = 100)
    private String headImageUuid;//头像存入服务器时使用的关键字
    @Transient
    @TableField(exist = false)
    private String headImageUrl;//头像地址
    @Transient
    @TableField(exist = false)
    private Boolean includeAfter = true;//根据部门查询员工时，是否包含下级部门
    @Transient
    @TableField(exist = false)
    private String token;
    @Transient
    @TableField(exist = false)
    private Collection<? extends GrantedAuthority> authorities;
    @Transient
    @TableField(exist = false)
    private boolean accountNonExpired;
    @Transient
    @TableField(exist = false)
    private boolean accountNonLocked;
    @Transient
    @TableField(exist = false)
    private boolean credentialsNonExpired;
    @Transient
    @TableField(exist = false)
    private boolean enabled;

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }

    public User toSafe() {
        this.setPassword(null);
        return this;
    }

}
